def run(params:list[str]):
    from sklearn import datasets,neighbors
    from sklearn.metrics import accuracy_score, precision_score,recall_score,f1_score
    from sklearn.metrics import mean_squared_error, r2_score

    from ApiBase import apiBase
    try:
        data=apiBase.argv_json(params,1,{"0.1,0.2":"0.1","0.3,0.4":"0.2","0.4,0.5":"0.2","0.6,0.7":"0.1","0.8,0.9":"0.1"})
        #apiBase.log("param1="+str(data))
        nbs=apiBase.dict("/mlknncls/n_neighbors",3)
        X_digits=[]
        y_digits=[]
        for key in data.keys():
            numbers = [float(num) for num in key.split(',')]
            X_digits.append(numbers)
            val=data[key]
            y_digits.append(val)

        ### 1.5.1 KNN分类
        # 加载digits手写数字数据集
        X_digits, y_digits = datasets.load_digits(return_X_y=True)
        #X_digits = X_digits / X_digits.max()

        n_samples = len(X_digits)

        #训练集和测试集划分
        X_train = X_digits[: int(0.9 * n_samples)]  #取前90%的数据作为训练集，其余作为测试集
        y_train = y_digits[: int(0.9 * n_samples)]
        X_test = X_digits[int(0.9 * n_samples) :]
        y_test = y_digits[int(0.9 * n_samples) :]

        #创建模型，KNeighborsClassifier分类器
        knn = neighbors.KNeighborsClassifier(n_neighbors=nbs)  #11个最近点                                                       
        
        #模型训练
        knn.fit(X_train, y_train) #对于分类问题，可以通过简单的多数投票法来确定预测类别

        #模型预测
        y_pred = knn.predict(X_test)

        ##评价指标
        import json
        retdata={}
        # accuracy
        retdata["accuracy_score"]=accuracy_score(y_test,y_pred)#不平衡类别分布的情况下可能会失效

        # precision指标
        retdata["precision_score"]=precision_score(y_test,y_pred,average='macro') #多分类，需要加average参数

        # recall_score指标
        retdata["recall_score"]=recall_score(y_test,y_pred,average='macro')

        #f1指标
        retdata["f1_score"]=f1_score(y_test,y_pred,average='macro')
        return json.dumps(retdata,ensure_ascii=False)
    except Exception as e:
        return f"function error:{e}"